﻿using System;
using System.Data;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;

using gKodes.Drawing;
using gKodes.Collections;
using gKodes.Windows.Forms;

namespace gKodes.HexView.Sample
{
    public partial class FOffsetStates : Form
    {
        private FMain mMain;

        public FOffsetStates(FMain main)
        {
            InitializeComponent();
            this.mMain = main;
            this.pBack.Click += new EventHandler(ChangeBackColor_Click);
            this.pFore.Click += new EventHandler(ChangeForeColor_Click);
            this.nUDSchems_ValueChanged(this.nUDSchems, EventArgs.Empty);
        }

        private void ColorChange_Click(object sender, EventArgs e)
        {
            if (this.cDMain.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                (sender as Panel).BackColor = this.cDMain.Color;
            }
        }

        private void ChangeForeColor_Click(object sender, EventArgs e)
        {
            this.mMain.hVMain.PaintSchemes.ChangeForePaint((int)this.nUDSchems.Value, (SolidPaint)this.cDMain.Color);
            this.mMain.hVMain.Invalidate();
        }

        private void ChangeBackColor_Click(object sender, EventArgs e)
        {
            this.mMain.hVMain.PaintSchemes.ChangeBackPaint((int)this.nUDSchems.Value, (SolidPaint)this.cDMain.Color);
            this.mMain.hVMain.Invalidate();
        }

        private void nUDSchems_ValueChanged(object sender, EventArgs e)
        {

            PaintScheme pS = this.mMain.hVMain.PaintSchemes[(int)this.nUDSchems.Value];
            this.pFore.BackColor = pS.Foreground.Color;
            this.pBack.BackColor = pS.Background.Color;
        }

        private void bAddRange_Click(object sender, EventArgs e)
        {
            String[] values = this.tBRange.Text.Split(',', '-');
            this.mMain.hVMain.IController
                .AddOffsetState(new Range(long.Parse(values[0]), long.Parse(values[1])), (int)this.nUDSchems.Value);
        }

        private void bRemoveRange_Click(object sender, EventArgs e)
        {
            String[] values = this.tBRange.Text.Split(',', '-');
            this.mMain.hVMain.IController
                .RemoveOffsetState(new Range(long.Parse(values[0]), long.Parse(values[1])), (int)this.nUDSchems.Value);
        }
    }
}
